home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / graphics / gnuplot / gnuplot-3.7.1doc / demo / spline.dem < prev    next >
Text File  |  1999-11-29  |  3KB  |  95 lines

  1. #
  2. # $Id: spline.dem,v 1.1.1.1.2.1 1999/10/11 13:24:09 lhecking Exp $
  3. #
  4. # Some curve plotting using common cubic polynomial basis function for cagd.
  5. #
  6. #                Gershon Elber, Aug. 1992
  7. #
  8. set xrang [0:1]
  9. set grid
  10. set key box
  11.  
  12. set yrange[-0.2:1.4]
  13. m0(x) = 1
  14. m1(x) = x
  15. m2(x) = x**2
  16. m3(x) = x**3
  17. set title "The cubic Monomial basis functions"
  18. plot m0(x), m1(x), m2(x), m3(x)
  19. pause -1 "Press return to continue"
  20.  
  21. h00(x) = x**2 * ( 2 * x - 3) + 1
  22. h01(x) = -x**2 * (2 * x - 3)
  23. h10(x) = x * (x - 1)**2
  24. h11(x) = x**2 * (x - 1)
  25.  
  26. set title "The cubic Hermite basis functions"
  27. plot h00(x), h01(x), h10(x), h11(x)
  28. pause -1 "Press return to continue"
  29.  
  30. bez0(x) = (1 - x)**3
  31. bez1(x) = 3 * (1 - x)**2 * x
  32. bez2(x) = 3 * (1 - x) * x**2
  33. bez3(x) = x**3
  34. set title "The cubic Bezier basis functions"
  35. plot bez0(x), bez1(x), bez2(x), bez3(x)
  36. pause -1 "Press return to continue"
  37.  
  38. bsp0(x) = ( 1 - 3 * x + 3 * x**2 - x**3 ) / 6;
  39. bsp1(x) = ( 4 - 6 * x**2 + 3 * x**3 ) / 6;
  40. bsp2(x) = ( 1 + 3 * x + 3 * x**2 - 3 * x**3 ) / 6
  41. bsp3(x) = x**3 / 6
  42. set title "The cubic uniform Bspline basis functions"
  43. plot bsp0(x), bsp1(x), bsp2(x), bsp3(x)
  44. pause -1 "Press return to continue"
  45.  
  46. y0 = 1
  47. y1 = 0.2
  48. y2 = 0.8
  49. y3 = 0
  50.  
  51. x0 = 0
  52. x1 = 0.33
  53. x2 = 0.66
  54. x3 = 1
  55.  
  56. xv0 = -0.3
  57. yv0 = 0.5
  58. xv1 = -0.4
  59. yv1 = 0.2
  60.  
  61. set arrow from x0,y0 to x1,y1 nohead
  62. set arrow from x1,y1 to x2,y2 nohead
  63. set arrow from x2,y2 to x3,y3 nohead
  64.  
  65. cub_bezier_x(t) = bez0(t) * x0 + bez1(t) * x1 + bez2(t) * x2 + bez3(t) * x3
  66. cub_bezier_y(t) = bez0(t) * y0 + bez1(t) * y1 + bez2(t) * y2 + bez3(t) * y3
  67. cub_bsplin_x(t) = bsp0(t) * x0 + bsp1(t) * x1 + bsp2(t) * x2 + bsp3(t) * x3
  68. cub_bsplin_y(t) = bsp0(t) * y0 + bsp1(t) * y1 + bsp2(t) * y2 + bsp3(t) * y3
  69.  
  70. set parametric
  71. set trange [0:1]
  72. set title "The cubic Bezier/Bspline basis functions in use"
  73. plot cub_bezier_x(t), cub_bezier_y(t) with lines 2,\
  74.      cub_bsplin_x(t), cub_bsplin_y(t) with lines 3
  75. pause -1 "Press return to continue"
  76.  
  77. set noarrow
  78. #
  79. # Note the arrows here, scaled by 1/3 so they will fit into plotting area
  80. #
  81. set arrow from x1,y1 to x1+xv0/3,y1+yv0/3
  82. set arrow from x2,y2 to x2+xv1/3,y2+yv1/3
  83. set arrow from x1,y1 to x1+xv0,y1+yv0
  84. set arrow from x2,y2 to x2+xv1,y2+yv1
  85.  
  86. cub_hermit_x1(t) = h00(t) * x1 + h01(t) * x2 + h10(t) * xv0 + h11(t) * xv1
  87. cub_hermit_y1(t) = h00(t) * y1 + h01(t) * y2 + h10(t) * yv0 + h11(t) * yv1
  88. cub_hermit_x2(t) = h00(t) * x1 + h01(t) * x2 + h10(t) * xv0*3 + h11(t) * xv1*3
  89. cub_hermit_y2(t) = h00(t) * y1 + h01(t) * y2 + h10(t) * yv0*3 + h11(t) * yv1*3
  90. set title "The cubic Hermite basis functions in use"
  91. plot cub_hermit_x1(t), cub_hermit_y1(t) with lines 2,\
  92.      cub_hermit_x2(t), cub_hermit_y2(t) with lines 3
  93. pause -1 "Press return to continue"
  94. reset
  95.